/*
*  封装根据路由id获取id分类名，详细信息
*/
import { getCategory } from '@/apis/category';
import { ref, onMounted } from 'vue'
import { useRoute, onBeforeRouteUpdate } from 'vue-router';


export function useCategory() {
    const categoryData = ref({})
    const route = useRoute()

    const getCategoryData = async (id) => {
        const res = await getCategory(id)
        categoryData.value = res.result
    }

    onMounted(() => {
        getCategoryData(route.params.id)
    })

    onBeforeRouteUpdate((to, from) => {
        getCategoryData(to.params.id)
    })

    return categoryData
}